class AdminController < WebappController
  before_filter :ensure_admin
  layout "admin"
  
  def index
    
  end
  
  private
  def ensure_admin
    #check if has session
    if session[:user_session]
      logger.debug "has session"
    else
      logger.debug "Dont have session"
    end
    if not has_session?
      flash_error(:not_allowed)
      session[:return_to] = request.request_uri
      redirect_to new_session_url
    else
      user = User.find(user_session.user_id)
      if not user.admin
        flash_error(:not_allowed)
        
        redirect_to_last_page        
      end
    end
  end
end
